﻿using FileToLINQ;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleSample
{

    [FileColumn(FieldIndex = 01, Property = "A", MaxLength = 34, UsePropertyAsName = true)]
    [FileColumn(FieldIndex = 02, Property = "B", MaxLength = 5, UsePropertyAsName = true, TextAlign = Align.Right,  FillChar = '0')]
    [FileColumn(FieldIndex = 03, Property = "C", UsePropertyAsName = true, MaxLength = 9, OutputFormat = "0000000.00", WithOutSeparator = true)]
    [FileColumn(FieldIndex = 04, Property = "D", MaxLength = 8, Name = "F", OutputFormat = "yyyyMMdd", FillChar = '0')]
    [FileColumn(FieldIndex = 05, Property = "E", UsePropertyAsName = true, MaxLength = 2, OutputFormat = "00")]
    public class Test
    {
       public string A { get; set; }
       public int B { get; set; }
       public decimal C { get; set; }
       public DateTime D { get; set; }
       public short E { get; set; }
      
    }

    class Program
    {

        static string m_Path = @"C:\";

        static void Main(string[] args)
        {
            cree();
            FileContext cc = new FileContext();

            IEnumerable<Test> tt = cc.Read<Test>(Path.Combine(m_Path, "test.csv"), new MainFrameFileDescription(';'));

            cc.Write<Test>(tt, Path.Combine(m_Path, "testRet.csv"), new MainFrameFileDescription());

        }

        static void cree()
        {
            HashSet<Test> lists = new HashSet<Test>();

            lists.Add( new Test() { A ="Vache", B= 5, C=25.4m, D = new DateTime(2014,05,12), E = 3 });
            lists.Add(new Test() { A = "train", B = 70, C = 100m, D = new DateTime(2013, 05, 12), E = 5 });
            lists.Add(new Test() { A = "voiture", B = 10, C = 6.01m, D = new DateTime(2012, 07, 18), E = 6 });
            lists.Add(new Test() { A = "Chat", B = 6, C = 658.5m, D = new DateTime(2014, 03, 1), E = 0 });
            lists.Add(new Test() { A = "Chien", B = 54, C = 4.56m, D = new DateTime(2014, 11, 25), E = 1 });


            FileContext cc = new FileContext();
            cc.Write<Test>(lists.AsEnumerable(), Path.Combine(m_Path, "test.csv"), new MainFrameFileDescription(';'));

        }

    }
}
